﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.TeamFoundation.Client;

namespace TShooter.TfsWord.TeamFoundation
{
    public class ProjectPicker
    {
        public ConnectionInfo GetProject()
        {
            return GetProject(null, null);
        }

        public ConnectionInfo GetProject(string defaultProject, Uri defaultTeamProjectCollection)
        {
            using (var picker = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false, new UICredentialsProvider()))
            {
                //if (defaultProject != null || defaultTeamProjectCollection != null)
                //{
                //    picker.SetDefaultSelectionProvider(new TeamProjectPickerDefaultSelectionProvider
                //                                           {
                                                               
                //                                           });
                //}

                if (picker.ShowDialog() == DialogResult.OK)
                {
                    if (picker.SelectedProjects != null && picker.SelectedProjects.Count() > 0)
                    {
                        return new ConnectionInfo
                                   {
                                       TeamProjectCollectionUri = picker.SelectedTeamProjectCollection.Uri,
                                       TeamProject = picker.SelectedProjects[0].Name
                                   };
                    }
                }
            }

            return null;
        }

        //private class TeamProjectPickerDefaultSelectionProvider: ITeamProjectPickerDefaultSelectionProvider
        //{
        //    private Uri _ServerUri;
        //    private Guid _ProjectGuid;

        //    public Uri GetDefaultServerUri()
        //    {
        //        throw new NotImplementedException();
        //    }

        //    public Guid? GetDefaultCollectionId(Uri instanceUri)
        //    {
        //        throw new NotImplementedException();
        //    }

        //    public IEnumerable<string> GetDefaultProjects(Guid collectionId)
        //    {
        //        throw new NotImplementedException();
        //    }
        //}
    }
}